package com.retail.alipay.config;

import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Author：开心就好
 * @Description:
 * @Date:2024/3/3
 */
@Configuration
public class ThreadPoolExecutorConfig {

    private final ThreadPoolExecutorEntity threadPoolExecutor;

    public ThreadPoolExecutorConfig(ThreadPoolExecutorEntity threadPoolExecutor) {
        this.threadPoolExecutor = threadPoolExecutor;
    }

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(
                threadPoolExecutor.getCorePoolSize(),
                threadPoolExecutor.getMaximumPoolSize(),
                5L, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(24)
        );
    }
}
